<template>
	<view class="page-body" :class="[app.setCStyle()]">
		<u-navbar v-if="like==1" :custom-back="return_s" title="签约合同"></u-navbar>
		<u-navbar v-if="like==0"  title="签约合同"></u-navbar>
		<!-- <view class="title">电子合同</view> -->
		<view class="detail-desc mt20 u-p-b-80 u-p-l-20 u-p-r-20">
			<u-parse :html="content"></u-parse>
			<!-- <rich-text :nodes="content"></rich-text> -->
		</view>
		<view v-if="userContract.is_signature == 1" class="sign-img bg-white mb40">
			<u-image height="320" :src="config.baseUrl + userContract.sign_img" mode="aspectFit"></u-image>
		</view>
		<view v-else class="sign">
			<u-button @click="showSignature = true" hover-class="none" shape="circle" class="gold-btn">我已阅读去签约</u-button>
		</view>
		
		<u-popup v-model="showSignature" mode="bottom">
			<view>		
				<signature @getImg="getImg" @cancelSign="cancelSign" width="750rpx" height="500rpx"></signature>
			</view>
		</u-popup>
	</view>
</template>


<script>
	import signature from '@/components/xiaolu-signature/index.vue';
	export default {
		components:{
			signature
		},
		data() {
			return {
				content:'',
				showSignature: false,
				isLoading: false,
				signImg: '',
				userContract: {},
				proxyContract: {},
				upgrade_type: 0,
				like:0
			}
		},
		onLoad(options) {
			if(options.like=="return"){
				this.like=1
			}
			this.proxy_id = options.proxy_id;
			this.upgrade_type = options.upgrade_type;
			this.getContract();
		},
		onShow() {
		},
		onReady() {},
		methods: {
			return_s(){
				uni.navigateTo({
					url: '/pages/member/center/index'
				});
			},
			getContract() { //获取合同信息
				let proxy_id = this.proxy_id;
				this.$u.post('channel/api.proxy_users/getContractInfo',{proxy_id:proxy_id}).then(res => {
					this.userContract = res.data.user_contract;
					this.proxyContract = res.data.proxy_contract;
					this.content = this.proxyContract.contract;
				}).catch(res => {
					this.app.showModal('请求错误', '/pagesB/channel/center/index', true);
				})
			},
			cancelSign(){
				this.showSignature = false;
			},
			getImg(img){
				let that = this;
				
				if (this.isLoading == true){
					return false;
				}
				this.isLoading = true;
				this.$u.post('channel/api.proxy_users/saveContract', 
					{
						sign_img:img,
						proxy_id: that.proxy_id,
						upgrade_type: that.upgrade_type
					}).then(res => {
					this.isLoading = false;
					this.showSignature = false;
					uni.showModal({
					    title: '提示',
					    content: res.msg,
						showCancel:false,
					    success: function (r) {
							that.getContract();
					    }
					});
				}).catch(res=>{
					this.isLoading = false;
				})
			}
		}
	}
</script>

<style lang="scss">

.title{
	margin-top: 20rpx;
	font-size: 32rpx;
	font-weight: bold;
	text-align: center;
}

/*  详情 */
	.detail-desc{
		background: #fff;
		margin-top: 16rpx;
		padding-bottom: 50rpx;
		img{
			width: 100%;
		}
	}
	
	.sign{
		position: fixed;
		bottom: 10rpx;
		left: 0;
		padding: 0 20rpx;
		width: 750rpx;
	}
</style>
